/**
 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Joins elements with delimeter
 *
 * @param arr array to be joined in String
 *
 * @param delimiter a string to insert between elements of arr
 *
 * @returns joined elements of arr with delimiter between
 */
{% if T != "boolean"%}
export function join(arr: {{T}}[], delimiter: String): String {
    let sb: StringBuilder = new StringBuilder();
    let len: int = arr.length;
    for (let i: int = 0; i < len; i++) {
        sb.append(arr[i])
        if (i != len - 1) {
            sb.append(delimiter);
        }
    }
    return sb.toString();
}
{% else %}
export function join(arr: boolean[], delimiter: String): String {
    let sb: StringBuilder = new StringBuilder();
    let len: int = arr.length;
    for (let i: int = 0; i < len; i++) {
        sb.append(arr[i] ? "true" : "false")
        if (i != len - 1) {
            sb.append(delimiter);
        }
    }
    return sb.toString();
}
{% endif %}
